$(document).ready(function() {
	$( ".information-container" ).addClass("ui-widget");
	$( ".button-invest-farmer" ).button();
	$( ".information-container h3, h4, .customNavigation, .information-content, .button-invest-farmer" ).hide().show("fade",1500);
	$( ".thumbnails div img" ).addClass("ui-corner-all ui-widget-content");
	var carousel = $(".carousel");
	var thumbnails = $(".thumbnails");
	carousel.owlCarousel({
		singleItem : true,
		slideSpeed : 1000,
		navigation: true,
		navigationText: [
			"<i><img src='images/left.png'></i>",
			"<i><img src='images/right.png'></i>"
		],
		pagination: false,
		afterAction : syncPosition,
		responsiveRefreshRate : 200,
	});
	thumbnails.owlCarousel({
		items : 6,
		itemsDesktop: [1199,6],
		itemsDesktopSmall: [979,6],
		itemsTablet: [768,6],
		itemsMobile: [479,6],
		pagination: false,
		responsiveRefreshRate : 100,
		afterInit : function(el){
		el.find(".owl-item").eq(0).addClass("synced");
	}
	});
	function syncPosition(el){
		var current = this.currentItem;
		$(".thumbnails")
		.find(".owl-item")
		.removeClass("synced")
		.eq(current)
		.addClass("synced")
		if($(".thumbnails").data("owlCarousel") !== undefined){
			center(current)
		}
	}
	$(".thumbnails").on("click", ".owl-item", function(e){
		e.preventDefault();
		var number = $(this).data("owlItem");
		carousel.trigger("owl.goTo",number);
	});
	function center(number){
		var thumbnailsvisible = thumbnails.data("owlCarousel").owl.visibleItems;
		var num = number;
		var found = false;
		for(var i in thumbnailsvisible){
			if(num === thumbnailsvisible[i]){
				var found = true;
			}
		}
		if(found===false){
			if(num>thumbnailsvisible[thumbnailsvisible.length-1]){
				thumbnails.trigger("owl.goTo", num - thumbnailsvisible.length+2)
			}else{
				if(num - 1 === -1){
					num = 0;
				}
				thumbnails.trigger("owl.goTo", num);
			}
		} else if(num === thumbnailsvisible[thumbnailsvisible.length-1]){
			thumbnails.trigger("owl.goTo", thumbnailsvisible[1])
		} else if(num === sync2visible[0]){
			thumbnails.trigger("owl.goTo", num-1)
		}
	}
});